package com.heyi.saas.start.config;

import com.heyi.saas.start.properties.TenantTableProperties;
import com.heyi.saas.start.service.TenantTables;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author dengfeng
 * @Description: 自动配置SAAS
 * @date 2021/9/1711:42
 */
@Configuration
//@ConditionalOnClass(TenantTables.class)
@ConditionalOnProperty(prefix = "saas.tenanttable",value = "enable",matchIfMissing = true)
@EnableConfigurationProperties(TenantTableProperties.class)
public class TenantTableAutoConfiguration {

    @Autowired
    private TenantTableProperties tenantTableProperties;

    @Bean
    @ConditionalOnMissingBean(TenantTables.class)
    public TenantTables getTenantTables() {
        TenantTables tenantTables = new TenantTables();
        tenantTables.setTenantTables(tenantTableProperties);
        return tenantTables;
    }

}
